package com.athena.controller {
	import com.athena.utils.Util;
	import com.athena.view.GameBoard;
	import flash.display.Sprite;
	/**
	 * ...
	 * @author chau
	 */
	public class Handle 
	{	
		private var intable : Boolean = false;
		public function Handle() 
		{
		}
		
		private function gotoTable(str : String, _v : Boolean = false, create : Boolean = false) : void {
			if (intable) {
				Main.getInstance().gameBoard.viewToJoin();
			}else {
				intable = true;
				if (Main.getInstance().gameBoard) {
					Main.getInstance().gameBoard.reset(str, _v, create);
				}else {
					Main.getInstance().gameBoard = new GameBoard(str, _v, create);
				}
				Main.getInstance().dashBoard.remove();
				Main.getInstance().addChild(Main.getInstance().gameBoard);
			}
		}
		private function gotoDashBoard() : void {
			intable = false;
			Main.getInstance().gameBoard.remove();
			Main.getInstance().dashBoard.addEvent();
			Main.getInstance().addChild(Main.getInstance().dashBoard.movie);
		}
		public function createTable(str : String) : void {
			//goto gameboad
			gotoTable(str, false, true);
			
			Util.removeLoad();
		}
		
		public function joinTable(str : String) : void {
			//goto gameboad
			gotoTable(str);
			
			Util.removeLoad();
		}
		
		public function otherJoinTable(str : String) : void {
			// app player
			Main.getInstance().gameBoard.otherJoinTable(str);
		}
		
		public function leaveTable(_id : *) : void {
			if (_id == Main.getInstance().currPlayer.displayName || _id == Main.getInstance().gameObject.TABLEID) {
				gotoDashBoard();
				return;
			}else {
				Main.getInstance().gameBoard.otherLeave(_id);
			}
			
		}
		
		public function readyTable(_name : String) : void {
			Main.getInstance().gameBoard.playerReady(_name);
		}
		public function ccTable(_name : String) : void {
			
		}
		public function vTable(str : String) : void {
			gotoTable(str, true);
		}
		
	}

}